#pragma config(Sensor, dgtl1,  Fsonar,         sensorSONAR_inch)
#pragma config(Sensor, dgtl3,  Lsonar,         sensorSONAR_inch)
#pragma config(Sensor, dgtl5,  Rsonar,         sensorSONAR_inch)
#pragma config(Sensor, dgtl7,  Ltch,           sensorTouch)
#pragma config(Sensor, dgtl8,  Rtch,           sensorTouch)
#pragma config(Motor,  port2,           RFmotor,       tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor,  port3,           RBmotor,       tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor,  port4,           LFmotor,       tmotorServoContinuousRotation, openLoop)
#pragma config(Motor,  port5,           LBmotor,       tmotorServoContinuousRotation, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main(){
while(true){

if ((SensorValue(Fsonar)<9 )&& (SensorValue(Fsonar)> 0 ) && ((SensorValue(Rsonar) > 10)||(SensorValue(Rsonar)<0))){
motor[LBmotor] = 127;
motor[LFmotor] = 127;
motor[RFmotor] = -127;
motor[RBmotor] = -127;
wait1Msec(1388);

}else if ((SensorValue(Fsonar)<9 )&& (SensorValue(Fsonar)> 0 ) && ((SensorValue(Lsonar) > 10)||(SensorValue(Lsonar)<0))){
motor[LBmotor] = -127;
motor[LFmotor] = -127;
motor[RBmotor] = 127;
motor[RFmotor] = 127;
wait1Msec(1390);

}else if ((SensorValue (Rsonar)<2 && SensorValue (Rsonar)>0) && (SensorValue(Fsonar)>5 || SensorValue(Fsonar)>0)){
motor[LBmotor] = 127;
motor[LFmotor] = 127;
motor[RFmotor] = 127;
motor[RBmotor] = 127;
wait1Msec(100);
}else if ((SensorValue (Lsonar)<2 && SensorValue (Lsonar)>0) && (SensorValue(Fsonar)>5 && SensorValue(Fsonar)>0)){
motor[LBmotor] = 127;
motor[LFmotor] = 127;
motor[RFmotor] = 127;
motor[RBmotor] = 127;
wait1Msec(100);
}else if ((SensorValue (Rtch)==1) && (SensorValue(Fsonar)>5 && SensorValue(Fsonar)>0)){
motor[LBmotor] = -127;
motor[LFmotor] = -127;
motor[RFmotor] = -127;
motor[RBmotor] = -127;
wait1Msec(100);
}else if ((SensorValue (Ltch)==1) && (SensorValue(Fsonar)>5 && SensorValue(Fsonar)>0)){
motor[LBmotor] = -127;
motor[LFmotor] = -127;
motor[RFmotor] = -127;
motor[RBmotor] = -127;
wait1Msec(100);
}else if((SensorValue(Fsonar)>5 || SensorValue(Fsonar)<0)  &&(SensorValue(Lsonar)>2 || SensorValue(Lsonar)<0) && (SensorValue(Rsonar)>2 || SensorValue(Rsonar)<0)){
motor[RBmotor] = 127;
motor[RFmotor] = 127;
motor[LBmotor] = 127;
motor[LFmotor] = 127;
}else if(SensorValue(Fsonar)>5 || SensorValue(Fsonar)<0){
motor[RBmotor] = 127;
motor[RFmotor] = 127;
motor[LBmotor] = 127;
motor[LFmotor] = 127;
}else{
motor[LBmotor] = 0;
motor[LFmotor] = 0;
motor[RFmotor] = 0;
motor[RBmotor] = 0;
}

}
}
